package com.wutuo.roster.provider.dao;

import cn.apestar.core.base.GenericMapper;
import cn.apestar.core.base.MapperAnnotation;
import com.wutuo.roster.provider.domain.Roster;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.type.JdbcType;

/**
 * 服务关系表 Dao 层
 *
 * @author lvh
 * @version 1.0
 */

@MapperAnnotation public interface BaseRosterMapper extends GenericMapper<Roster, Long> {

    @Override @Delete({"delete from roster", "where id = #{id,jdbcType=BIGINT}"})
    int deleteByPrimaryKey(Long id);

    @Override @Options(useGeneratedKeys = true, keyProperty = "id")
    @Insert({"insert into roster (", "teacher_id,", "cm_institution_id,", "create_by,",
        "create_date,", "update_by,", "update_date,", "remarks,", "del_flag,", "name,", "photo,",
        "sex,", "tg_zt,", "grade,", "year", " )values(", "#{teacherId,jdbcType=BIGINT},",
        "#{cmInstitutionId,jdbcType=BIGINT},", "#{createBy,jdbcType=BIGINT},",
        "#{createDate,jdbcType=DATE},", "#{updateBy,jdbcType=BIGINT},",
        "#{updateDate,jdbcType=DATE},", "#{remarks,jdbcType=VARCHAR},",
        "#{delFlag,jdbcType=VARCHAR},", "#{name,jdbcType=VARCHAR},", "#{photo,jdbcType=VARCHAR},",
        "#{sex,jdbcType=VARCHAR},", "#{tgZt,jdbcType=VARCHAR},", "#{grade,jdbcType=VARCHAR},",
        "#{year,jdbcType=BIGINT})"}) int insert(Roster record);

    @InsertProvider(type = BaseRosterSqlProvider.class, method = "insertSelective")
    int insertSelective(Roster record);

    @Override
    @Select({"select", "id,", "teacher_id,", "cm_institution_id,", "create_by,", "create_date,",
        "update_by,", "update_date,", "remarks,", "del_flag,", "name,", "photo,", "sex,", "tg_zt,",
        "year", "from roster", "where id = #{id,jdbcType=BIGINT}"})
    @Results({@Result(column = "id", property = "id", jdbcType = JdbcType.BIGINT, id = true),
        @Result(column = "teacher_id", property = "teacherId", jdbcType = JdbcType.BIGINT),
        @Result(column = "cm_institution_id", property = "cmInstitutionId", jdbcType = JdbcType.BIGINT),
        @Result(column = "create_by", property = "createBy", jdbcType = JdbcType.BIGINT),
        @Result(column = "create_date", property = "createDate", jdbcType = JdbcType.DATE),
        @Result(column = "update_by", property = "updateBy", jdbcType = JdbcType.BIGINT),
        @Result(column = "update_date", property = "updateDate", jdbcType = JdbcType.DATE),
        @Result(column = "remarks", property = "remarks", jdbcType = JdbcType.VARCHAR),
        @Result(column = "del_flag", property = "delFlag", jdbcType = JdbcType.VARCHAR),
        @Result(column = "name", property = "name", jdbcType = JdbcType.VARCHAR),
        @Result(column = "photo", property = "photo", jdbcType = JdbcType.VARCHAR),
        @Result(column = "sex", property = "sex", jdbcType = JdbcType.VARCHAR),
        @Result(column = "tg_zt", property = "tgZt", jdbcType = JdbcType.VARCHAR),
        @Result(column = "year", property = "year", jdbcType = JdbcType.BIGINT)})
    Roster selectByPrimaryKey(Long id);

    @Override
    @UpdateProvider(type = BaseRosterSqlProvider.class, method = "updateByPrimaryKeySelective")
    int updateByPrimaryKeySelective(Roster record);

    @Override @Update({"update roster", "set ", "teacher_id = #{teacherId,jdbcType=BIGINT},",
        "cm_institution_id = #{cmInstitutionId,jdbcType=BIGINT},",
        "create_by = #{createBy,jdbcType=BIGINT},", "create_date = #{createDate,jdbcType=DATE},",
        "update_by = #{updateBy,jdbcType=BIGINT},", "update_date = #{updateDate,jdbcType=DATE},",
        "remarks = #{remarks,jdbcType=VARCHAR},", "del_flag = #{delFlag,jdbcType=VARCHAR},",
        "name = #{name,jdbcType=VARCHAR},", "photo = #{photo,jdbcType=VARCHAR},",
        "sex = #{sex,jdbcType=VARCHAR},", "tg_zt = #{tgZt,jdbcType=VARCHAR},",
        "year = #{year,jdbcType=BIGINT}", "grade = #{grade,jdbcType=VARCHAR},",
        "where id = #{id,jdbcType=BIGINT}"}) int updateByPrimaryKey(Roster record);
}